﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DBLClient.DBLAdminConfigService;
namespace DBLClient.DBLForm
{
    public partial class AddUserLevelForm : Form
    {
        private string EditMode = string.Empty;
        private int userlevelid;
        public AddUserLevelForm(string mode,int userlevelid)
        {
            InitializeComponent();

            this.EditMode = mode;
            if (mode.Equals("A"))
            {
                //新增
            }
            else if(mode.Equals("U"))
            {
                this.userlevelid = userlevelid;
                AdminConfigService admin = new AdminConfigService();
                DataSet ds = admin.GetUserLevelByID(userlevelid);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    textBoxUserLevelName.Text = (ds.Tables[0].Rows[0]["userlevelname"]).ToString();
                    numericUpDownPicCount.Value = Convert.ToInt32(ds.Tables[0].Rows[0]["piccount"]);
                    numericUpDownBaseMark.Value = Convert.ToInt32(ds.Tables[0].Rows[0]["basemark"]);
                }
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            //收集数据
            string userlevelname = string.Empty;
            int piccount;
            int basemark;

            userlevelname = textBoxUserLevelName.Text;
            piccount = Convert.ToInt32( numericUpDownPicCount.Value);
            basemark = Convert.ToInt32( numericUpDownBaseMark.Value);


            int affectnum = 0;
            if (EditMode.Equals("A"))
            {
                //新增
                AdminConfigService admin = new AdminConfigService();
                affectnum = admin.AddUserLevel(userlevelname, piccount, basemark);

            }
            else if (EditMode.Equals("U"))
            {
                //修改
                AdminConfigService admin = new AdminConfigService();
                affectnum = admin.UpdateUserLevel(userlevelid, userlevelname, piccount, basemark);
            }
            if (affectnum == 1)
            {
                MessageBox.Show("更改成功");
            }
            else
            {
                MessageBox.Show("更改失败");
            }
        }
    }
}
